﻿//********************************************************************************//
//创建日期：<创建日期，2016-06-18>
//创建作者：<郭登杰，guodengjie@shanghai3h.com>
//功能说明: 打印数据导出 地下水
//********************************************************************************//
layui.use(['form', 'jquery', 'element', 'laydate'], function () {
    var form = layui.form()
    , layer = layui.layer
    , $ = layui.jquery
    , element = layui.element()
    , laydate = layui.laydate;
    /*initial load start*/
    initcontrol();
    /*initial load end*/

    /*initial*/
    function initcontrol() {
        //获取当前账务年月
        $.ajax({
            type: "post",
            cache: false,
            async: false,
            url: "/ashx/Common.ashx",
            data: {
                "op": "QSZWYM"
            },
            dataType: "json",
            success: function (rs) {
                $("#cZWYM").val(rs.Data1);
            },
            error: function (error) {
                layer.msg(error.responseText);
            }
        });

    }
    /*end initial*/

    /*event*/
    $("#oSearch").click(function () {
            load();
    });
    
    //导出
    $("#oExport").click(function () {
        if($("#ContentList1 .datarow").length==0)
        {
            layer.msg("没有可供导出的数据");
            return;
        }
        var zwym=$("#cZWYM").val();
        var type=$("#cType").val();
        var quyu=$("#cType").val()=="2"?$("#cQY").val():0;
        var url = "/ashx/QSQT/QiTa.ashx?op=DAYINSJDC_Export&zwym=" + zwym + "&type=" + type + "&quyu=" + quyu;
        $("iframe").remove();
        var iframe = "<iframe style='display:none' src='" + url + "'></iframe>"
        $("body").append(iframe);
    });
    /*
    //导出
    $("#oExport").click(function () {
        if ($("#ContentList1 .datarow").length == 0) {
            layer.msg("没有可供导出的数据");
            return;
        }
        var zwym = $("#cZWYM").val();
        var type = $("#cType").val();
        var quyu = $("#cType").val() == "2" ? $("#cQY").val() : 0;
        $.ajax({
            type: "post",
            cache: false,
            async: false,
            url: "/ashx/QSQT/QiTa.ashx",
            data: {
                "op": "DAYINSJDC_Export",
                "zwym": $("#cZWYM").val(),
                "type": $("#cType").val(),
                "quyu": $("#cType").val() == "2" ? $("#cQY").val() : 0 //其他账单默认大陆
            },
            dataType: "text",
            success: function (rs) {
                $("iframe").remove();
                var iframe = "<iframe style='display:none' src='" + rs + "'></iframe>"
                $("body").append(iframe);
            },
            error: function (error) {
                layer.msg(error.responseText);
            }
        });        
    });
    */
    form.on('select(cType)', function (data) {
        if (data.value == "2") {
            $("#cQYL").show();
            $("#cQYD").show();
        }
        else {
            $("#cQYL").hide();
            $("#cQYD").hide();
        }
        if (data.value == "0") {
            $("#thLast").show();
        }
        else {
            $("#thLast").hide();
        }
        load();
    });
    form.on('select(cQY)', function (data) {
        load();
    });
    function load() {
        var rss = "";
        $.ajax({
            type: "post",
            cache: false,
            async: false,
            url: "/ashx/QSQT/QiTa.ashx",
            data: {
                "op": "DAYINSJDC",
                "zwym": $("#cZWYM").val(),
                "type": $("#cType").val(),
                "quyu": $("#cType").val()=="2"?$("#cQY").val():0 //其他账单默认大陆
            },
            dataType: "json",
            success: function (rs) {
                rss = rs;
                if ($("#cType").val() == "0") {
                    $("#ContentList1 th").eq(18).text("老表号");
                }
                else {
                    $("#ContentList1 th").eq(18).text("备注");
                }
            },
            error: function (error) {
                layer.msg(error.responseText);
            }
        });
        $("#ContentList1").find(".datarow").remove();
        if (rss.length > 0) {
            chunk(rss, list1Create, null);
        }
        else {
            $("#ls1Count").text("0");
            $("#ls1JESum").text("0.00");
        }
    }
 
    function list1Create(rs, i) {
        $("#ContentList1").append(createItemStr1(rs));
        $("#ls1Count").text($("#ContentList1 .datarow").length);
        var jeSum = 0;
        $("#ContentList1 .datarow").each(function () {
            jeSum = jeSum + parseFloat($(this).find("td").eq(12).text());
        });
        $("#ls1JESum").text(jeSum.toFixed(2));
    }
    function createItemStr1(obj) {
        var str = $("#ItemStr1 tr").prop("outerHTML");        
        var itemstr,
        Y, M, YHH, YHM, DIZHI, YOUBIAN, YHZH, KHHM, KHYH, BYCM, KPS, DANJIA, JINE, DAXIEJE, ZDBH, JIAOKUANR, TSBZ,FYLX, BZ, LXR, CWHM, XJRQ;
        Y = obj["Y"];
        M = obj["M"];
        YHH = obj["YHH"];
        YHM = obj["YHM"];
        DIZHI = obj["DIZHI"];
        YOUBIAN = obj["YOUBIAN"];
        YHZH = obj["YHZH"];
        KHHM = obj["KHHM"];
        KHYH = obj["KHYH"];
        BYCM = obj["BYCM"];
        KPS = obj["KPS"];
        DANJIA = obj["DANJIA"];
        JINE = obj["JINE"];
        DAXIEJE = obj["DAXIEJE"];
        ZDBH = obj["ZDBH"];
        JIAOKUANR = obj["JIAOKUANR"];
        TSBZ = obj["TSBZ"];
        FYLX = obj["FYLX"];
        BZ = obj["BZ"];
        LXR = obj["LXR"];
        CWHM = obj["CWHM"];
        XJRQ = obj["XJRQ"]["DateString"];
        if ($("#cType").val() != "0") {
            str = str.replace("<td vid=\"tdLast\">XJRQ</td>", "");
        }
        itemstr = str.replace(new RegExp("objY", "gm"), Y)
                     .replace(new RegExp("objM", "gm"), M)
                     .replace(new RegExp("YHH", "gm"), YHH)
                     .replace(new RegExp("YHM", "gm"), YHM)
                     .replace(new RegExp("DIZHI", "gm"), DIZHI)
                     .replace(new RegExp("YOUBIAN", "gm"), YOUBIAN)
                     .replace(new RegExp("YHZH", "gm"), YHZH)
                     .replace(new RegExp("KHHM", "gm"), KHHM)
                     .replace(new RegExp("KHYH", "gm"), KHYH)
                     .replace(new RegExp("BYCM", "gm"), BYCM)
                     .replace(new RegExp("KPS", "gm"), KPS)
                     .replace(new RegExp("DANJIA", "gm"), parseFloat(DANJIA).toFixed(2))
                     .replace(new RegExp("JINE", "gm"), parseFloat(JINE).toFixed(2))
                     .replace(new RegExp("DAXIEJE", "gm"), DAXIEJE)
                     .replace(new RegExp("ZDBH", "gm"), ZDBH)
                     .replace(new RegExp("JIAOKUANR", "gm"), JIAOKUANR)
                     .replace(new RegExp("TSBZ", "gm"), TSBZ)
                     .replace(new RegExp("FYLX", "gm"), FYLX)
                     .replace(new RegExp("BEIZHU", "gm"), BZ)
                     .replace(new RegExp("LXR", "gm"), LXR)
                     .replace(new RegExp("CWHM", "gm"), CWHM)
                     .replace(new RegExp("XJRQ", "gm"), XJRQ)
        ;
        
        return itemstr;
    }
    /*event end*/

    function verify() {
        return true;
    }
    /*logic end*/
});